using Godot;
using System;
using MonsterDiKe.common;

namespace MonsterDiKe.player.script;

public partial class StateWalk : BaseState
{

    /**
     * 玩家移动速度
     */
    private float _moveSpeed = 100.0f;

    /**
     * 玩家闲置状态机
     */
    private StateIdle _stateIdle;

    public override void _Ready()
    {
        _stateIdle = GetParent().GetNode<Node>("Idle") as StateIdle;
    }

    public override void Init()
    {
        base.Init();
    }

    public override void Enter()
    {
        // 播放行走动画
        GlobalInitializationNode.Player.UpdateAnimation(PlayerAnimationPrefixNameConst.Walk);
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override BaseState Process(double delta)
    {
        Player player = GlobalInitializationNode.Player;
        // 将角色没有速度时返回闲置状态
        if (player.Direction.Equals(Vector2.Zero)) return _stateIdle;
        // 设置角色速度
        player.Velocity = player.Direction * _moveSpeed;
        // 更新角色朝向及对应动画
        if (player.UpdatePlayerDirection())
        {
            player.UpdateAnimation(PlayerAnimationPrefixNameConst.Walk);
        }
        return null;
    }

    public override BaseState PhysicsProcess(double delta)
    {
        return base.PhysicsProcess(delta);
    }

    public override BaseState HandleInput(InputEvent @event)
    {
        return base.HandleInput(@event);
    }
}
